<?
require_once("cms/core/helper/bean/Abstract.php");
require_once("cms/gallery/om/GalleryImagePeer.php");
require_once("cms/gallery/om/GalleryPeer.php");
require_once("cms/core/om/ImagePeer.php");
require_once("cms/core/om/BinaryFilePeer.php");

class PHP_CMS_View_Helper_GalleryImages extends AbstractList {

    public function galleryImages($form=null) {

        if($this->isInit)
            return $this;

        parent::init($form);

        $this->criteria->clearSelectColumns();

        $this->criteria->addSelectColumn(GalleryImagePeer::GALLERY_IMAGE_ID);
        $this->criteria->addSelectColumn(GalleryImagePeer::CAPTION);
        $this->criteria->addSelectColumn(GalleryImagePeer::POSITION);
        $this->criteria->addSelectColumn(GalleryImagePeer::INSERT_DATE);
        $this->criteria->addSelectColumn(GalleryImagePeer::MODIFIED_DATE);
        $this->criteria->addSelectColumn(GalleryImagePeer::THUMBNAIL_ID);
        $this->criteria->addSelectColumn(GalleryImagePeer::IMAGE_ID);
        $this->criteria->addSelectColumn(GalleryImagePeer::GALLERY_ID);
        $this->criteria->addSelectColumn(GalleryImagePeer::ACTIVE);

        $this->criteria->addSelectColumn(ImagePeer::IMAGE_ID);
        $this->criteria->addSelectColumn(ImagePeer::WIDTH);
        $this->criteria->addSelectColumn(ImagePeer::HEIGHT);
        $this->criteria->addSelectColumn(ImagePeer::INSERT_DATE);
        $this->criteria->addSelectColumn(ImagePeer::MODIFIED_DATE);
        $this->criteria->addSelectColumn(ImagePeer::BINARY_FILE_ID);

        $this->criteria->addSelectColumn(BinaryFilePeer::BINARY_FILE_ID);
        $this->criteria->addSelectColumn(BinaryFilePeer::FILE_NAME);
        $this->criteria->addSelectColumn(BinaryFilePeer::FILE_SIZE);
        $this->criteria->addSelectColumn(BinaryFilePeer::CONTENT_TYPE);

        $this->criteria->addJoin(ImagePeer::BINARY_FILE_ID, BinaryFilePeer::BINARY_FILE_ID);

        $this->criteria->add(GalleryImagePeer::GALLERY_ID, $form->getId());
        $this->criteria->setDistinct();

        if($form->getOrder() == GalleryImagePeer::POSITION) {
            $this->form->setDirection("asc");
        }

        return $this;

    }

    public function getGallery() {
        return GalleryPeer::retrieveByPk($this->form->getId());
    }


    /**
     * Define the propel peer we are going to use to list
     * page items.
     */
    public function getMethod() {
        return "doSelectJoinImageRelatedByImageId";
    }


    /**
     * Define the propel peer we are going to use to list
     * page items.
     */
    public static function getPeer() {
        return new GalleryImagePeer();
    }


    /**
     * Return the searchable fields for this list page.
     */
    public static function getFields() {
        return array(
            GalleryImagePeer::CAPTION,
            BinaryFilePeer::FILE_NAME,
            GalleryPeer::INSERT_DATE,
            GalleryPeer::MODIFIED_DATE
        );
    }
}
?>